package org.kingtop.mybatis.mapper;

/**
 * @author 陈金波
 * @date 2018/1/30 21:43
 */
public enum SqlMethodEnum {
    //查
    /**根据主键查询数据*/
    SELECT_ONE_BY_PK("getById", "SELECT %s FROM %s WHERE %s = #{%s}"),
    /**根据多个主键查询数据，多个主键通过id隔开*/
    SELECT_LIST_BY_PKS("listByIds", "<script>SELECT %s FROM %s WHERE %s in %s</script>"),
    /**根据条件查询数据*/
    SELECT_LIST_BY_BEAN("listByBean", "<script>SELECT %s FROM %s %s %s</script>"),
    /**查询所有的数据*/
    SELECT_LIST_ALL("listAll", "SELECT %s FROM %s"),
    /**根据条件查询数据，分页*/
    SELECT_PAGE_BY_BEAN("pageByBean", "<script>SELECT %s FROM %s %s %s</script>"),
    //增
    /**插入数据*/
    INSERT("add", "INSERT INTO %s(%s) VALUES(%s)"),
    //改
    /**通过主键更新指定数据的所有字段*/
    UPDATE_BY_PK("update", "UPDATE %s SET %s WHERE %s"),
    /**通过主键更新指定数据的所有非空字段*/
    UPDATE_FOR_NOT_NULL_BY_PK("updateForNotNull", "<script>UPDATE %s <trim prefix=\"set\" suffixOverrides=\",\">%s</trim> WHERE %s</script>"),
    //删
    /**通过主键删除指定数据*/
    DELETE_BY_PK("deleteById", "DELETE FROM %s WHERE %s = #{%s}"),
    /**删除指定的多个主键的数据*/
    DELETE_BY_PKS("deleteByIds", "<script>DELETE FROM %s WHERE %s IN %s</script>"),
    /**通过指定条件删除多条数据*/
    DELETE_BY_BEAN("deleteByBean", "<script>DELETE FROM %s %s</script>"),
    ;

    private final String methodId;
    private final String sql;

    SqlMethodEnum(String methodName, String sql) {
        this.methodId = methodName;
        this.sql = sql;
    }

    public String getMethodId() {
        return methodId;
    }

    public String getSql() {
        return sql;
    }
}
